/*
 *             Copyright (C) 2024 Steve Jrong
 *
 * 	   GitHub Homepage: https://www.github.com/SteveJrong
 *      Gitee Homepage: https://gitee.com/stevejrong1024
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stevejrong.waiter.common.component;

import com.stevejrong.waiter.common.component.util.DateTimeUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;

/**
 * 基类 - 领域事件发布
 *
 * @author Steve Jrong
 * @since 1.0
 */
@ToString
public abstract class AbstractDomainEvent<T> {

    /**
     * 领域事件的唯一ID
     * <p>
     * 要求全局唯一，用于唯一标识事件、多上下文间交互传递等唯一标识
     */
    private final String uniqueId;

    /**
     * 领域事件的创建时间
     */
    private final LocalDateTime createDateTime;

    /**
     * 领域事件的标识（事件名称）
     * <p>
     * 用于给事件定义一个名称，好做区分
     */
    private final String eventName;

    /**
     * 领域事件携带的数据
     */
    @Getter
    @Setter
    private T data;

    public abstract String uniqueId();

    public abstract String eventName();

    protected AbstractDomainEvent() {
        this.uniqueId = uniqueId();
        this.createDateTime = DateTimeUtil.getLocalDateTimeByNow();
        this.eventName = eventName();
    }
}